package com.inspur.edp.common.expr.expresses.calculate;


import com.inspur.edp.common.expr.Express;
import com.inspur.edp.common.expr.ExpressDSLGenerator;
import com.inspur.edp.common.expr.ExpressDSLGeneratorMgr;
import com.inspur.edp.common.expr.ast.ASTContext;

/**
 * @author lizhaorui
 * @description TODO
 * @date 2024/12/16 19:33
 */
public class CalculateDSL implements ExpressDSLGenerator {

    @Override
    public String getKind() {
        return CalculateExpr.KIND;
    }

    @Override
    public String generate(ASTContext context, Express express) {
        CalculateExpr calculateExpr = (CalculateExpr) express;
        StringBuilder sb = new StringBuilder();
        String operator = calculateExpr.getOperator().toDSL();
        int index = 0;
        for (Express expressItem : calculateExpr.getExpresses()) {
            if (index > 0) {
                sb.append(operator);
            }
            sb.append(ExpressDSLGeneratorMgr.generateDsl(context, expressItem));
            index++;
        }
        return sb.toString();
    }
}
